import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.FileOutputStream;
import java.io.IOException;

public class writeExcelExample {
    public static void main(String[] args)  {
        try (Workbook workbook = new XSSFWorkbook()) {
            //创建工作表
            Sheet sheet = workbook.createSheet("第一个sheet");
            //创建一行
            Row headerRow = sheet.createRow(0);
            //创建单元格
            Cell headerCell = headerRow.createCell(0);
            headerCell.setCellValue("姓名");
            Cell headerCell1 = headerRow.createCell(1);
            headerCell1.setCellValue("年龄");
            Row dataRow = sheet.createRow(1);
            dataRow.createCell(0).setCellValue("张三");
            dataRow.createCell(1).setCellValue(23);
            try(FileOutputStream fileOutputStream=new FileOutputStream("my_first_excel.xlsx")){
                workbook.write(fileOutputStream);
            }


        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
